home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / internet / other / ka9q / ka9q_src.arc / LAPBTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-28  |  2.0 KB  |  94 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "ax25.h"
  4. #include "timer.h"
  5. #include "lapb.h"
  6.  
  7. /* Called whenever timer T1 expires */
  8. void
  9. recover(n)
  10. int *n;
  11. {
  12.     register struct ax25_cb *axp;
  13.     char control;
  14.     struct mbuf *bp;
  15.  
  16.     axp = (struct ax25_cb *)n;
  17.     if(axp->n2 != 0 && axp->retries++ >= axp->n2){
  18.         /* Retry count exceeded; reset the link, unless
  19.          * a connect or disconnect was pending, in which case
  20.          * just give up.
  21.          */
  22.         switch(axp->state){
  23.         case DISCONNECTED:
  24.             break;        /* The user issued a double disc */
  25.         case SETUP:
  26.         case DISCPENDING:
  27.             lapbstate(axp,DISCONNECTED);    /* Just give up */
  28.             del_ax25(axp);
  29.             break;
  30.         case CONNECTED:
  31.         case FRAMEREJECT:
  32.             lapbstate(axp,SETUP);
  33.              sendctl(axp,COMMAND,SABM|PF);    /* Attempt link reset */
  34.             break;
  35.         }
  36.         return;
  37.     }
  38.     switch(axp->state){
  39.     case SETUP:
  40.         sendctl(axp,COMMAND,SABM|PF);
  41.         break;
  42.     case FRAMEREJECT:
  43.         frmr(axp,0,0);
  44.         break;
  45.     case DISCPENDING:
  46.         sendctl(axp,COMMAND,DISC|PF);
  47.         break;
  48.     case CONNECTED:
  49.         /* Don't wait for a Final reply if running the old protocol */
  50.         if(axp->proto == V2)
  51.             axp->waitack = YES;
  52.         if(axp->txq != NULLBUF){
  53.             /* Retransmit oldest unacked I-frame */
  54.             dup_p(&bp,axp->txq,0,len_mbuf(axp->txq));
  55.             control = PF | I | ((axp->vs - axp->unack) & MMASK) << 1
  56.              | axp->vr << 5;
  57.             sendframe(axp,COMMAND,control,bp);
  58.         } else {
  59.             /* Transmit poll */
  60.             control = len_mbuf(axp->rxq) > axp->window ? RNR|PF : RR|PF;
  61.             sendctl(axp,COMMAND,control);
  62.         }
  63.         break;
  64.     }
  65. }
  66.  
  67. /* T2 has expired, we can't delay an acknowledgement any further */
  68. void
  69. send_ack(n)
  70. int *n;
  71. {
  72.     char control;
  73.     register struct ax25_cb *axp;
  74.  
  75.     axp = (struct ax25_cb *)n;
  76.     control = len_mbuf(axp->rxq) > axp->window ? RNR : RR;
  77.     sendctl(axp,RESPONSE,control);
  78.     axp->response = 0;
  79. }
  80.  
  81. /* Send a poll (S-frame command with the poll bit set) */
  82. void
  83. pollthem(n)
  84. int *n;
  85. {
  86.     char control;
  87.     register struct ax25_cb *axp;
  88.  
  89.     axp = (struct ax25_cb *)n;
  90.     axp->waitack = YES;
  91.     control = len_mbuf(axp->rxq) > axp->window ? RNR|PF : RR|PF;
  92.     sendctl(axp,COMMAND,control);
  93. }
  94.